import pymysql


def main():
    try:
        con = pymysql.connect(user="root", host="localhost", passwd="as", database="gjtjj")
    except ConnectionError:
        raise ConnectionError("数据库连接错误！")

    cursor = con.cursor()

    sql = """
        CREATE TABLE IF NOT EXISTS population_info(
        province VARCHAR(20) comment '省份',
        total VARCHAR(20) comment '合计',
        household VARCHAR(20) comment '家庭户' ,
        collectively VARCHAR(20) comment '集体户' ,
        pop_total VARCHAR(20) comment '人口合计' ,
        male VARCHAR(20) comment '男' ,
        female VARCHAR(20) comment '女' ,
        sex_ratio VARCHAR(20) comment '性别比(女=100)' ,
        household_sub_total VARCHAR(20) comment '家庭户小计' ,
        household_male VARCHAR(20) comment '男(家庭户)' ,
        household_female VARCHAR(20) comment '女(家庭户)' ,
        household_sex_ratio VARCHAR(20) comment '性别比(女=100)(家庭户)' ,
        collectively_sub_total VARCHAR(20) comment '集体户小计' ,
        collectively_male VARCHAR(20) comment '男(集体户)' ,
        collectively_female VARCHAR(20) comment '女(集体户)' ,
        collectively_sex_ratio VARCHAR(20) comment '性别比(女=100)(集体户)' ,
        average_household VARCHAR(20) comment '平均家庭户规模' 
        ) comment 'China2010人口资料';
        """

    cursor.execute(sql)
    cursor.close()
    con.close()

main()